package com.zpark.ribbon.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @PackageName: com.zpark.ribbon.controller
 * @ClassName: Ribbon01Controller
 * @Description:
 * @author: RZS
 * @date: 2022/11/17  16:40
 */
@RestController
@RequestMapping("/ribbon")
public class Ribbon01Controller {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private LoadBalancerClient loadBalancerClient;

    private final static String URL = "http://server-ribbon/server";

    @RequestMapping("/p")
    public String getP(){
        return restTemplate.getForObject(URL + "/port", String.class);
    }

    @RequestMapping("/choose")
    public Object getChoose(){
        return loadBalancerClient.choose("SERVER-RIBBON");
    }

}
